package com.example.changtest

import com.example.changtest.test.Calculator
import org.junit.*
import org.junit.rules.Timeout

import org.junit.Rule
import java.lang.Exception


/**
 * @Description:https://www.jianshu.com/p/437790996694
 * @author: zcs
 * @email: 1059737741@qq.com
 * create at 2022/1/25 13:49
 */
class CalculatorTest {
    companion object{
        lateinit var calculator: Calculator
        var count = 0
        var count1 = 0

        @BeforeClass
        @JvmStatic
        fun setup(){
            calculator = Calculator()
            count += 1
            println("Before 运行${count}次")

        }

        @AfterClass
        @JvmStatic
        fun cleanup(){
            count1 += 1
            println("After 运行${count1}次")
        }
    }


    // 验证异常
    @Test(expected = IllegalArgumentException:: class)
    fun testDivide(){
        calculator.divide(2,0)
    }

    @Test
    fun testPlus(){
        val result1 = calculator.plus(1,1)
        Assert.assertEquals(2,result1)
    }

    @Test
    @Ignore("not implemented yet")
    fun testSubtract() {

    }

    @Test
    fun testFail() {
        Assert.fail()
        //Assert.fail(message)
    }

//    @Rule
//    public var timeout = Timeout(1000) //使用Timeout这个 Rule，
//
//    //每个 testMethod 的运行时间都不会长于 1 秒钟。
//    @Test
//    @Throws(Exception::class)
//    fun testMethod1() {
//        //your tests
//    }


}